package com.lianboke.link.ad.httpProxyUtils;

import android.content.Context;


import com.lianboke.link.ad.utils.KLog;
import com.lianboke.link.ad.utils.StringUtils;
import com.lianboke.link.ad.utils.ToastUtil;

import static org.wuji.wujivpninterface.changeip;
import static org.wuji.wujivpninterface.closeip;
import static org.wuji.wujivpninterface.init;
import static org.wuji.wujivpninterface.login;
/**
 * 无极代理工具类
 * Created by admin on 2017/9/11.
 */

public class WJProxyUtils {
    private Context mActContext;

    public WJProxyUtils(Context con) {
        mActContext = con;
    }

    /**
     * 初始化无极vpn
     * @return
     */
    public int initWJProxy(){
        try {
            String strInitResult = init(mActContext);
            KLog.e("--------init--------------------------:" + strInitResult);
            if (strInitResult.startsWith("0:")) {
                //初始化成功
                return 0;
            } else if (strInitResult.startsWith("3:")) {
                //正在运行，不能重复初始化
                return 0;
            } else {
                return -1;
            }
        }catch (Exception e){
            return -1;
        }
    }

    /**
     *
     * @return
     */
    public int loginWJProxy(String userName,String userPwd,int zyzx,int duli) {
        try {
            String logiRresult = login(mActContext, userName, userPwd, zyzx, duli);
            KLog.e("--------login--------------------------:" + logiRresult);
            if (logiRresult.startsWith("0:") || logiRresult.startsWith("3:")) {
                //登陆成功
                return 0;
            } else {
                return -1;
            }
        }catch (Exception e){
            return -1;
        }
    }

    /**
     * 切换ip 地址
     * @return
     */
    public String[] changeIpWJProxy(){
        try {
            String changeResult = changeip(mActContext);
            String[] result = new String[2];
            KLog.e("--------changeip--------------------------:" + changeResult);
            if (changeResult.startsWith("0:")) {
                result[0] = "0";
                result[1] = StringUtils.getIpAddresByWJ(changeResult);
                KLog.e("--------changeip---------------ip-----------:" + result[1]);
                return result;
            } else if(changeResult.startsWith("3:2")){
                result[0] = "3";
                result[1] = "2";
                return result;
            }else {
                result[0] = "-1";
                result[1] = "0";
                return result;
            }
        }catch (Exception e){
            String[] result = new String[2];
            result[0] = "-1";
            result[1] = "0";
            return result;
        }

    }

    /**
     * 关闭ip
     * 关闭ip
     */
    public String closedIpWJProxy(){
        try {
            String closeResult = closeip(mActContext);
            KLog.e("--------closeip--------------------------:" + closeResult);
            return closeResult;
        }catch (Exception e){
            return "-1";
        }
    }

}
